-----------------------------------------------
-- Project		: ECE 251 FINAL PROJECT
-- Author 		: Mahmut Yilmaz
-- Last Modified: 04/01/2007
-----------------------------------------------

LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_unsigned.all;
USE work.all;

ENTITY add_packet_header IS
	PORT (	clock			: IN  STD_LOGIC;	-- PosEdge Clock used	
			start			: IN  STD_LOGIC;	-- Resets the flop to 0, active HIGH
			N				: IN  STD_LOGIC_VECTOR (15 DOWNTO 0) ;	-- Flop input
      		q	 			: OUT STD_LOGIC_VECTOR (3 DOWNTO 0) 	-- Flop output
			);
END add_packet_header;

ARCHITECTURE behav OF add_packet_header IS
	SIGNAL header : STD_LOGIC_VECTOR (159 DOWNTO 0);
	SIGNAL counter: STD_LOGIC_VECTOR (7 DOWNTO 0);
	SIGNAL stop_now: STD_LOGIC;
BEGIN
	
	header <= x"100000000000200000000000BAAAAAAAAAAAAAAA";
	
	PROCESS (start, clock)
	BEGIN
		IF start = '0' THEN
			q <= x"0";
			counter <= x"01";
			stop_now <= '0';
		ELSIF (clock'EVENT AND clock='1' AND stop_now='0') THEN -- @ PosEdge Clock
			CASE counter IS
				WHEN x"01" =>
				    q <= header(3 DOWNTO 0);
				WHEN x"02" =>
				    q <= header(7 DOWNTO 4);
				WHEN x"03" =>
				    q <= header(11 DOWNTO 8);
				WHEN x"04" =>
				    q <= header(15 DOWNTO 12);
				WHEN x"05" =>
				    q <= header(19 DOWNTO 16);
				WHEN x"06" =>
				    q <= header(23 DOWNTO 20);
				WHEN x"07" =>
				    q <= header(27 DOWNTO 24);
				WHEN x"08" =>
				    q <= header(31 DOWNTO 28);
				WHEN x"09" =>
				    q <= header(35 DOWNTO 32);
				WHEN x"0A" =>
				    q <= header(39 DOWNTO 36);
				WHEN x"0B" =>
				    q <= header(43 DOWNTO 40);
				WHEN x"0C" =>
				    q <= header(47 DOWNTO 44);
				WHEN x"0D" =>
				    q <= header(51 DOWNTO 48);
				WHEN x"0E" =>
				    q <= header(55 DOWNTO 52);
				WHEN x"0F" =>
				    q <= header(59 DOWNTO 56);
				WHEN x"10" =>
				    q <= header(63 DOWNTO 60);
				WHEN x"11" =>
				    q <= header(67 DOWNTO 64);
				WHEN x"12" =>
				    q <= header(71 DOWNTO 68);
				WHEN x"13" =>
				    q <= header(75 DOWNTO 72);
				WHEN x"14" =>
				    q <= header(79 DOWNTO 76);
				WHEN x"15" =>
				    q <= header(83 DOWNTO 80);
				WHEN x"16" =>
				    q <= header(87 DOWNTO 84);
				WHEN x"17" =>
				    q <= header(91 DOWNTO 88);
				WHEN x"18" =>
				    q <= header(95 DOWNTO 92);
				WHEN x"19" =>
				    q <= header(99 DOWNTO 96);
				WHEN x"1A" =>
				    q <= header(103 DOWNTO 100);
				WHEN x"1B" =>
				    q <= header(107 DOWNTO 104);
				WHEN x"1C" =>
				    q <= header(111 DOWNTO 108);
				WHEN x"1D" =>
				    q <= header(115 DOWNTO 112);
				WHEN x"1E" =>
				    q <= header(119 DOWNTO 116);
				WHEN x"1F" =>
				    q <= header(123 DOWNTO 120);
				WHEN x"20" =>
				    q <= header(127 DOWNTO 124);
				WHEN x"21" =>
				    q <= header(131 DOWNTO 128);
				WHEN x"22" =>
				    q <= header(135 DOWNTO 132);
				WHEN x"23" =>
				    q <= header(139 DOWNTO 136);
				WHEN x"24" =>
				    q <= header(143 DOWNTO 140);
				WHEN x"25" =>
				    q <= header(147 DOWNTO 144);
				WHEN x"26" =>
				    q <= header(151 DOWNTO 148);
				WHEN x"27" =>
				    q <= header(155 DOWNTO 152);
				WHEN x"28" =>
				    q <= header(159 DOWNTO 156);
				WHEN x"29" =>
				    q <= N(3 DOWNTO 0);
				WHEN x"2A" =>
				    q <= N(7 DOWNTO 4);
				WHEN x"2B" =>
				    q <= N(11 DOWNTO 8);
				WHEN x"2C" =>
				    q <= N(15 DOWNTO 12);
				WHEN OTHERS =>
					stop_now <= '1';
			END CASE;
			counter <= counter + 1;
		END IF;
	END PROCESS;
END behav;
